<?php

    class objects_model extends MY_Model
    {
        var $objects_partners_destinations_objecttype ="SELECT
        objects.ID as object_ID,
        objects.name as object_name,
        objects.fields as object_fields,
        objects.information as object_info,
        destinations.ID as destination_ID,
        destinations.name as destination_name,
        object_type.ID as object_type_ID,
        object_type.type as object_type_type,
        gallery.path as gallery_path,
        pictures.filename as picture_filename
        FROM objects
        LEFT JOIN destinations ON objects.destinations_ID = destinations.ID
        LEFT JOIN object_type ON objects.object_type_ID = object_type.ID
        LEFT JOIN objects_gallery ON objects.ID = objects_gallery.objects_ID
        LEFT JOIN gallery ON objects_gallery.gallery_ID = gallery.ID
        LEFT JOIN pictures ON gallery.ID = pictures.gallery_ID
        AND pictures.ID=
        (
        SELECT pictures.ID
        FROM pictures
        WHERE pictures.gallery_ID = gallery.ID
        ORDER BY pictures.order ASC, pictures.ID ASC
        LIMIT 0, 1  
        )
        ";

        function __construct()
        {
            parent::__construct();
            $this->table = 'objects';
        }

        function list_all()
        {
            $q = $this->objects_partners_destinations_objecttype;

            $res = $this->db->query($q)->result_array();
            return $res;

        }

        function list_by_id($object_id)
        {
            $q = $this->objects_partners_destinations_objecttype;
            $q .= "WHERE objects.ID = $object_id";

            $res = $this->db->query($q)->row_array();
            return $res;
        }
    }

?>
